/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package chuiniurobot.message;

import com.alibaba.fastjson.JSON;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import org.apache.mina.core.session.IoSession;

/**
 * 开始摇动骰子的消息
 * @author zhengji
 */
public class ShakeDiceMessage extends BaseMessage{

    public ShakeDiceMessage(IoSession ioSession, String requestJSONStr) {
        super(ioSession, requestJSONStr);
    }

    @Override
    public void execute() {
        
        //生成随机数
         String[] diceNumbers = new String[5];
        
          Random random = new Random();
          for(int i = 0; i < 5;i++) 
         {
             diceNumbers[i]=String.valueOf(random.nextInt(6) +1);
              // System.out.println(random.nextInt(6) +1);
         }
          this.setSelfDiceNumbers(diceNumbers);
         Map<String,String> map=new HashMap<String,String>(); 
        
         map.put("cmd", BaseMessage.DiceNumberCommand);
         
         map.put("d", this.toStringSplitByComma(diceNumbers));
         map.put("id", String.valueOf(this.getPlayerId()));
         
         this.sendMessage(map);//发送摇定好的骰子点数
         
     }
    

}
